home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1 / Nebula One.iso / Communications / pcomm / Source / chg_dir.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-06-12  |  1.5 KB  |  76 lines

  1. /*
  2.  * Open a window to prompt for a new directory.  Checks to see you have
  3.  * search permission.
  4.  */
  5.  
  6. #include <curses.h>
  7. #include "config.h"
  8. #include "misc.h"
  9.  
  10. void
  11. chg_dir()
  12. {
  13.     extern int fd;
  14.     WINDOW *ch_win, *newwin();
  15.     char *ans, *dir, *expand(), *cwd, *getcwd(), cwdbuf[200];
  16.     char *get_str();
  17.  
  18.     cwd = getcwd(cwdbuf, 200);
  19.  
  20.     ch_win = newwin(6, 70, 5, 5);
  21.  
  22.     mvwprintw(ch_win, 2, 4, "Current directory: %s", cwd);
  23.     mvwaddstr(ch_win, 3, 4, "New directory: ");
  24.     box(ch_win, VERT, HORZ);
  25.  
  26.     mvwattrstr(ch_win, 0, 3, A_BOLD, " Change directory ");
  27.     wmove(ch_win, 3, 19);
  28.     wrefresh(ch_win);
  29.                     /* get the answer */
  30.     while ((ans = get_str(ch_win, 80, "", " \t\n")) != NULL) {
  31.                     /* a CR means no change */
  32.         if (*ans == '\0')
  33.             break;
  34.                     /* expand the input */
  35.         dir = expand(ans);
  36.                     /* if you have search permission */
  37.         if (!access(dir, 1)) {
  38.             if (!chdir(dir))
  39.                 break;
  40.         }
  41.         beep();
  42.         mvwattrstr(ch_win, 4, 15, A_BOLD, "No such directory or no access permission");
  43.         wrefresh(ch_win);
  44.         wait_key(ch_win, 3);
  45.                     /* clean up the mess */
  46.         clear_line(ch_win, 3, 19, TRUE);
  47.         clear_line(ch_win, 4, 14, TRUE);
  48.         wmove(ch_win, 3, 19);
  49.         wrefresh(ch_win);
  50.     }
  51.     if (fd == -1) {
  52.         werase(ch_win);
  53.         wrefresh(ch_win);
  54.     }
  55.     delwin(ch_win);
  56.     return;
  57. }
  58.  
  59. #ifdef BSD
  60. /*
  61.  * Get the current working directory, AT&T style.  Well... not really, it
  62.  * doesn't handle a NULL pointer for the buffer.
  63.  */
  64.  
  65. /* ARGSUSED */
  66. char *
  67. getcwd(buf, len)
  68. char *buf;
  69. int len;
  70. {
  71.     char *getwd();
  72.  
  73.     return(getwd(buf));
  74. }
  75. #endif /* BSD */
  76.